package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.pojo.Member;
import com.itheima.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhouwei
 * @date 2020-01-07 8:47
 */
@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;

    /**
     *查询是否为会员
     * @param telephone
     * @return
     */
    @Override
    public Member findMember(String telephone) {
        Member member = memberDao.findByTelephone(telephone);
        return member;
    }

    /**
     * 注册member
     * @param member
     */
    @Override
    public void addMember(Member member) {
        //密码加密
        if(member.getPassword()!=null){
            member.setPassword(MD5Utils.md5(member.getPhoneNumber()));
        }
        memberDao.add(member);
    }

    /**
     * 查询月份对应会员人数
     * @param months
     * @return
     */
    @Override
    public List<Integer> findMemberByDate(List<String> months) {
        List<Integer> list =new ArrayList<>();
        for(String month:months){
            month=month+"-31";
            int count=memberDao.findCountByMonth(month);
            list.add(count);
        }
        return list;
    }
}
